package tech.$2306.comment.model.dto;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import java.io.Serializable;
import java.util.Date;
import lombok.Data;
import org.apache.logging.log4j.util.Strings;
import org.springframework.beans.BeanUtils;
import tech.$2306.comment.model.vo.output.MessageOutput;

/**
 * 留言板类
 * @TableName message
 */
@TableName(value ="message")
@Data
public class MessageDTO implements Serializable {
    /**
     * 消息编号
     */
    @TableId(type = IdType.AUTO)
    private Integer messageId;

    /**
     * 消息标题
     */
    private String messageTitle;

    /**
     * 消息发布者昵称
     */
    private String messageNickName;

    /**
     * 消息内容
     */
    private String messageContent;

    /**
     * 消息发送者IP
     */
    private String messagePostIp;

    /**
     * 消息发送者IP省
     */
    private String messageAddressProvince;

    /**
     * 消息发送者IP市
     */
    private String messageAddressCity;

    /**
     * 消息发布者IP县
     */
    private String messageAddressCounty;

    /**
     * 消息发送者运营商
     */
    private String messageIsp;

    /**
     * 消息发送时间
     */
    private Date messageTime;

    /**
     * 逻辑删除消息
     */
    private Integer deleted;

    public MessageOutput getMessageOutput() {
        MessageOutput output = new MessageOutput();
        BeanUtils.copyProperties(this,output);
        if (Strings.isNotBlank(output.getMessagePostIp())) {
            String ip = output.getMessagePostIp();
            String[] split = ip.split("\\.");
            if (split.length >= 2) {
                split[2] = "*";
                split[3] = "*";
            }
            System.out.println(String.join(".",split));
            output.setMessagePostIp(String.join(".",split));
        }
        return output;
    }



    @TableField(exist = false)
    private static final long serialVersionUID = 1L;

    @Override
    public boolean equals(Object that) {
        if (this == that) {
            return true;
        }
        if (that == null) {
            return false;
        }
        if (getClass() != that.getClass()) {
            return false;
        }
        MessageDTO other = (MessageDTO) that;
        return (this.getMessageId() == null ? other.getMessageId() == null : this.getMessageId().equals(other.getMessageId()))
            && (this.getMessageTitle() == null ? other.getMessageTitle() == null : this.getMessageTitle().equals(other.getMessageTitle()))
            && (this.getMessageNickName() == null ? other.getMessageNickName() == null : this.getMessageNickName().equals(other.getMessageNickName()))
            && (this.getMessageContent() == null ? other.getMessageContent() == null : this.getMessageContent().equals(other.getMessageContent()))
            && (this.getMessagePostIp() == null ? other.getMessagePostIp() == null : this.getMessagePostIp().equals(other.getMessagePostIp()))
            && (this.getMessageAddressProvince() == null ? other.getMessageAddressProvince() == null : this.getMessageAddressProvince().equals(other.getMessageAddressProvince()))
            && (this.getMessageAddressCity() == null ? other.getMessageAddressCity() == null : this.getMessageAddressCity().equals(other.getMessageAddressCity()))
            && (this.getMessageAddressCounty() == null ? other.getMessageAddressCounty() == null : this.getMessageAddressCounty().equals(other.getMessageAddressCounty()))
            && (this.getMessageIsp() == null ? other.getMessageIsp() == null : this.getMessageIsp().equals(other.getMessageIsp()))
            && (this.getMessageTime() == null ? other.getMessageTime() == null : this.getMessageTime().equals(other.getMessageTime()))
            && (this.getDeleted() == null ? other.getDeleted() == null : this.getDeleted().equals(other.getDeleted()));
    }

    @Override
    public int hashCode() {
        final int prime = 31;
        int result = 1;
        result = prime * result + ((getMessageId() == null) ? 0 : getMessageId().hashCode());
        result = prime * result + ((getMessageTitle() == null) ? 0 : getMessageTitle().hashCode());
        result = prime * result + ((getMessageNickName() == null) ? 0 : getMessageNickName().hashCode());
        result = prime * result + ((getMessageContent() == null) ? 0 : getMessageContent().hashCode());
        result = prime * result + ((getMessagePostIp() == null) ? 0 : getMessagePostIp().hashCode());
        result = prime * result + ((getMessageAddressProvince() == null) ? 0 : getMessageAddressProvince().hashCode());
        result = prime * result + ((getMessageAddressCity() == null) ? 0 : getMessageAddressCity().hashCode());
        result = prime * result + ((getMessageAddressCounty() == null) ? 0 : getMessageAddressCounty().hashCode());
        result = prime * result + ((getMessageIsp() == null) ? 0 : getMessageIsp().hashCode());
        result = prime * result + ((getMessageTime() == null) ? 0 : getMessageTime().hashCode());
        result = prime * result + ((getDeleted() == null) ? 0 : getDeleted().hashCode());
        return result;
    }

    @Override
    public String toString() {
        StringBuilder sb = new StringBuilder();
        sb.append(getClass().getSimpleName());
        sb.append(" [");
        sb.append("Hash = ").append(hashCode());
        sb.append(", messageId=").append(messageId);
        sb.append(", messageTitle=").append(messageTitle);
        sb.append(", messageNickName=").append(messageNickName);
        sb.append(", messageContent=").append(messageContent);
        sb.append(", messagePostIp=").append(messagePostIp);
        sb.append(", messageAddressProvince=").append(messageAddressProvince);
        sb.append(", messageAddressCity=").append(messageAddressCity);
        sb.append(", messageAddressCounty=").append(messageAddressCounty);
        sb.append(", messageIsp=").append(messageIsp);
        sb.append(", messageTime=").append(messageTime);
        sb.append(", deleted=").append(deleted);
        sb.append(", serialVersionUID=").append(serialVersionUID);
        sb.append("]");
        return sb.toString();
    }
}